//登陆验证码
function myReload() {
    document.getElementById("myImage").src = 'CheckCode' + '?' + Math.random();
    console.log(document);
}

//对ajax请求URL路径进行封装，统一路径管理
function getRequestURL(myinterface) {
    var URL_Local = 'http://localhost:9096/web/' + myinterface;
    var Cloud_Server = 'http://49.233.164.24:8080/WebLogin/' + myinterface;
    return URL_Local;
}

//全局加载
window.onload = function () {
    var login = getid('login');
    var cancel = getid('Cancel');
    var class_loginFace = getclass('loginFace');
    login.onclick = function () {
        class_loginFace.style.display = 'block';
    }
    cancel.onclick = function () {
        class_loginFace.style.display = 'none';
    }
    // 登录功能的实现
    var login1 = getid('login1');
    // 原生方法（1）：获取form表单的验证码
    var form_obj = document.loginform;
    var login_checkcode = form_obj.checkcode;
    // 原生方法（2）：DOM
    var login_username = getid('username');
    // 其三：Jquery:
    var login_password = $('#password');
    login1.onclick = function () {
        $.ajax({
            xhrFields: {
                withCredentials: true
            },
            // header: {
            //     cookie: 'JSESSIONID=782E3061E66C38994AF326A23022E72D'
            // },
            type: "POST",
            url: 'user/login',
            data: {
                username: login_username.value,
                password: hex_md5(login_password.val()),
                checkcode: login_checkcode.value
            },
            success: function (data) {
                if (data.statusCode === 1) {
                    window.location = 'user/logged';
                } else {
                    alert(data.msg);
                }

            },
            error: function (err) {
                alert('服务器繁忙，请稍后再试！');
            }
        })
    }
}

